﻿package view.selectView.control
{
    import com.core.*;
    import com.core.destroy.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.net.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.newteam.model.*;
    import plugin.social.consts.*;
    import plugin.union.*;
    import uiresource.*;
    import view.mornExtends.*;
    import view.selectView.*;
    import vo.*;

    public class SelectViewUIControl extends SelectViewUI
    {
        private var list:List;
        private var _curSelect:Object;
        private var canclik:Boolean;
        private var data:Object;
        private var skillBuffers:Dictionary;
        private var bufferY:int = 85;
        private var _menuData1:Array;
        private var _curimg:String = null;
        private var _curimg2:String = null;
        private var mostors:Object;
        private var cfg:Object;
        private var imgname:String = "";
        private var _imgMpWidth:Number;
        private var _imgHpWidth:Number;
        private var _headRect2:Rectangle;
        private var _maskRect:Rectangle;
        private var _neimaskRect:Rectangle;
        private var _bossBlood:BossBlood;
        private var currMid:int;
        private static const HEAD_URL:String = "assets/images/head/";

        public function SelectViewUIControl()
        {
            this.skillBuffers = new Dictionary();
            this._menuData1 = ["查看信息", "邀请组队", "申请入队", "发起交易", "添加好友", "发起私聊", "邀请入会"];
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this._bossBlood = new BossBlood(bossBlood);
            var _loc_1:* = Control.create(SelectViewControl, this);
            ModelProxy.addObserver("selectView", _loc_1);
            this.init();
            this.addListener();
            return;
        }// end function

        private function init() : void
        {
            myMenu1.visible = false;
            this.list = myMenu1.getChildAt(1) as List;
            rolehead.x = 2;
            rolehead.y = -6;
            var _loc_1:* = new Sprite();
            _loc_1.graphics.beginFill(0, 1);
            _loc_1.graphics.drawCircle(0, 0, 30);
            _loc_1.graphics.endFill();
            _loc_1.x = 11 + 36;
            _loc_1.y = 10 + 36;
            this.head1.addChild(_loc_1);
            this.rolehead.mask = _loc_1;
            _loc_1 = new Sprite();
            _loc_1.graphics.beginFill(0, 1);
            _loc_1.graphics.drawCircle(0, 0, 30);
            _loc_1.graphics.endFill();
            _loc_1.x = 20 + 30;
            _loc_1.y = 18 + 30;
            this.bossheadCon.addChild(_loc_1);
            this.bosshead.mask = _loc_1;
            this._headRect2 = new Rectangle(0, 0, 240, 19);
            this._maskRect = new Rectangle(0, 0, 140, 13);
            this._neimaskRect = new Rectangle(0, 0, 118, 10);
            this._hpMcPanel.scrollRect = this._maskRect;
            this._mpMcPanel.scrollRect = this._neimaskRect;
            this.x = int(GlobalLayer.instance.root.stageWidth - 350 >> 1);
            myMenu1.x = 167;
            myMenu1.y = 73;
            return;
        }// end function

        private function addListener() : void
        {
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.onResize2);
            closeBtn.addEventListener(MouseEvent.CLICK, this.dispose);
            bossclose.addEventListener(MouseEvent.CLICK, this.dispose);
            _btn_Handle.addEventListener(MouseEvent.CLICK, this.youHandler);
            _btn_Team.addEventListener(MouseEvent.CLICK, this.otherMenu);
            _btn_Look.addEventListener(MouseEvent.CLICK, this.lookHandler);
            _btn_Friend.addEventListener(MouseEvent.CLICK, this.teamHandler);
            _btn_you.addEventListener(MouseEvent.CLICK, this.friendHandler);
            GlobalLayer.instance.root.addEventListener(MouseEvent.MOUSE_UP, this.closeMenu);
            this.list.array = this._menuData1;
            this.list.renderHandler = new Handler(this.onMenuFill);
            this.list.selectHandler = new Handler(this.MenuClickHander1);
            return;
        }// end function

        protected function friendHandler(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("social", CMDSocial.APPLYFOR, this.data.rid);
            return;
        }// end function

        protected function closeMenu(event:MouseEvent) : void
        {
            this.myMenu1.visible = false;
            return;
        }// end function

        protected function mouseDown(event:MouseEvent) : void
        {
            if (event.currentTarget != myMenu1)
            {
                this.myMenu1.visible = false;
            }
            return;
        }// end function

        private function showact(param1:Boolean) : void
        {
            _btn_Look.visible = param1;
            _btn_Friend.visible = param1;
            _btn_Team.visible = param1;
            _btn_Handle.visible = param1;
            this.canclik = param1;
            if (param1)
            {
                this.bufferY = 85;
            }
            else
            {
                this.bufferY = 65;
            }
            return;
        }// end function

        public function selectRole(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:String = null;
            var _loc_5:Array = null;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            if (param1.type != 10 && param1.type != 13)
            {
                return;
            }
            this._curSelect = param1;
            this.imgname = "normal";
            var _loc_2:* = UserData.getUserData();
            if (_loc_2.mapid != 10521)
            {
                bossclose.visible = true;
            }
            else
            {
                bossclose.visible = false;
            }
            if (this.mostors == null)
            {
                this.mostors = ConfigDictionary.data.monster;
            }
            if (param1.type == 10)
            {
                _txtName.text = param1.name;
                _txtCarrer.text = param1.level;
                this.showact(true);
                this.imgname = param1.career + "_" + param1.sex;
                head1.visible = true;
                bossheadCon.visible = false;
                _txtLv.text = param1.level + "级";
                if (this._curimg != this.imgname)
                {
                    this._curimg = this.imgname;
                    this.rolehead.url = Config.getUrl(HEAD_URL + this.imgname + ".png");
                }
                if (param1.ability)
                {
                    _txtHp.text = param1.ability.hp + "/" + param1.ability.maxHp;
                    _txtMp.text = int(param1.ability.innerPower) + "/" + int(param1.ability.maxInnerPower);
                    this._maskRect.width = int(param1.ability.hp / param1.ability.maxHp * 139);
                    _hpMcPanel.scrollRect = this._maskRect;
                    this._neimaskRect.width = int(param1.ability.innerPower / param1.ability.maxInnerPower * 118);
                    _mpMcPanel.scrollRect = this._neimaskRect;
                }
                else
                {
                    _txtHp.text = "0/0";
                    _txtMp.text = "0/0";
                    this._maskRect.width = 139;
                    _hpMcPanel.width = 118;
                    _hpMcPanel.scrollRect = this._maskRect;
                }
                this.visible = true;
            }
            else if (param1.type == 13)
            {
                bossname.text = param1.name;
                this.imgname = this.mostors[param1.mid].head;
                head1.visible = false;
                bosslist.visible = false;
                if (param1.mid != this.currMid)
                {
                    if (this.mostors[param1.mid].dropshow)
                    {
                        this.currMid = param1.mid;
                        _loc_3 = ConfigDictionary.data.item;
                        _loc_4 = this.mostors[param1.mid].dropshow;
                        _loc_5 = _loc_4.split("#");
                        _loc_6 = [];
                        _loc_7 = 0;
                        while (_loc_7 < _loc_5.length)
                        {
                            
                            if (_loc_3[_loc_5[_loc_7]])
                            {
                                _loc_8 = ItemObject.create(_loc_3[_loc_5[_loc_7]]);
                                if (_loc_8 && _loc_8.career == _loc_2.career)
                                {
                                    _loc_6.push(_loc_8);
                                }
                            }
                            _loc_7++;
                        }
                        bosslist.visible = true;
                        bosslist.array = _loc_6;
                        bosslist.renderHandler = new Handler(this.bossHandler);
                    }
                }
                else
                {
                    bosslist.visible = true;
                }
                bossheadCon.visible = true;
                this.showact(false);
                if (this._curimg2 != this.imgname)
                {
                    this._curimg2 = this.imgname;
                    this.bosshead.url = Config.getUrl(HEAD_URL + this.imgname + ".png");
                }
                if (this.data != param1)
                {
                    this.visible = false;
                    this._bossBlood.tubes = param1.hpShow;
                }
                if (param1.ability)
                {
                    bossbloodtxt.text = param1.ability.hp + "/" + param1.ability.maxHp;
                    bossmptxt.text = "50000/50000";
                    this._bossBlood.setBlood(param1.ability.hp, param1.ability.maxHp, !this.visible);
                }
                else
                {
                    bossbloodtxt.text = "0/0";
                    bossmptxt.text = "0/0";
                    this._bossBlood.setBlood(0, 0, !this.visible);
                    this.currMid = 0;
                }
                this.visible = true;
            }
            if (this.data == param1)
            {
                return;
            }
            this.data = param1;
            this.clearBuffers();
            this.initBuffers(param1);
            return;
        }// end function

        private function bossHandler(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:FlashItem = null;
            if (param2 < bosslist.array.length)
            {
                _loc_3 = bosslist.array[param2];
                _loc_4 = param1.getChildByName("fi") as FlashItem;
                _loc_4.data = _loc_3;
            }
            return;
        }// end function

        private function clearBuffers() : void
        {
            var _loc_1:SelectViewBufferItem = null;
            for each (_loc_1 in this.skillBuffers)
            {
                
                if (_loc_1 && _loc_1.parent)
                {
                    _loc_1.parent.removeChild(_loc_1);
                }
            }
            DestroyUtil.destroyMap(this.skillBuffers);
            return;
        }// end function

        public function initBuffers(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            this.cfg = ConfigDictionary.data.buffer;
            var _loc_2:* = ModelProxy.getValue("data", "servertime") + getTimer();
            if (param1.hasOwnProperty("beBuffers"))
            {
                for (_loc_3 in param1.beBuffers)
                {
                    
                    _loc_4 = -1;
                    if (param1.beBuffers[_loc_3].removetime > 0)
                    {
                        _loc_4 = int((param1.beBuffers[_loc_3].removetime - _loc_2) / 1000);
                    }
                    this.addSkillBuffer({bufferid:_loc_3, dispelTime:_loc_4});
                }
            }
            return;
        }// end function

        public function addSkillBuffer(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:SelectViewBufferItem = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            if (!this.cfg)
            {
                this.cfg = ConfigDictionary.data.buffer;
            }
            var _loc_2:* = this.cfg[param1.bufferid];
            if (_loc_2 && _loc_2.show == 1)
            {
                if (this.skillBuffers[param1.bufferid])
                {
                    this.removeSkillBuffer(param1.bufferid);
                }
                return;
                _loc_4.x = _loc_5 * 24 + 102;
                _loc_4.y = this.bufferY + 38;
                this.addChild(_loc_4);
                this.skillBuffers[param1.bufferid] = _loc_4;
            }
            return;
        }// end function

        public function removeSkillBuffer(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_3:SelectViewBufferItem = null;
            if (this.skillBuffers[param1])
            {
                if (this.skillBuffers[param1].parent)
                {
                    this.skillBuffers[param1].parent.removeChild(this.skillBuffers[param1]);
                    this.skillBuffers[param1].dispose();
                    delete this.skillBuffers[param1];
                    _loc_2 = 0;
                    for each (_loc_3 in this.skillBuffers)
                    {
                        
                        _loc_3.x = _loc_2 * 24 + 85;
                        _loc_2++;
                    }
                }
            }
            return;
        }// end function

        private function MenuClickHander1(param1:int) : void
        {
            switch(param1)
            {
                case 0:
                {
                    Server.instance.send(114, 7, this.data.rid, 0, ConnectType.SYSTEM);
                    break;
                }
                case 1:
                {
                    PluginManager.instance.sendToServer("team", CMDteam.TEAM_INVITE, this.data.rid);
                    break;
                }
                case 2:
                {
                    PluginManager.instance.sendToServer("team", CMDteam.TEAM_APPLY, this.data.rid);
                    break;
                }
                case 3:
                {
                    ModelProxy.change("plugin", "sendSysMsg", {name:"business", param:this.data.rid, cmd:1});
                    break;
                }
                case 4:
                {
                    PluginManager.instance.sendToServer("social", CMDSocial.APPLYFOR, this.data.rid);
                    break;
                }
                case 5:
                {
                    ModelProxy.change("chat", "pritalk", this.data);
                    break;
                }
                case 6:
                {
                    UnionSender._19unionInvite(this.data.rid);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            myMenu1.visible = false;
            return;
        }// end function

        private function closeHandler() : void
        {
            ModelProxy.change("zone", "cancelSelect", null);
            return;
        }// end function

        public function clearSelect() : void
        {
            this.dispose(null);
            return;
        }// end function

        public function updateRole(param1:Object) : void
        {
            this.selectRole(param1);
            return;
        }// end function

        private function youHandler(event:MouseEvent) : void
        {
            this.list.selectedIndex = -1;
            myMenu1.visible = true;
            return;
        }// end function

        private function onMenuFill(param1:Component, param2:int) : void
        {
            if (param2 < this.list.length)
            {
                (param1.getChildByName("label") as Label).text = this.list.array[param2];
                if (!param1.hasEventListener(MouseEvent.MOUSE_OVER))
                {
                    param1.addEventListener(MouseEvent.MOUSE_OVER, this.onBoxOverHandler);
                    param1.addEventListener(MouseEvent.MOUSE_OUT, this.onBoxOutHandler);
                }
            }
            return;
        }// end function

        private function onBoxOverHandler(event:MouseEvent) : void
        {
            (event.currentTarget.getChildByName("label") as Label).color = "0xfff7af";
            return;
        }// end function

        private function onBoxOutHandler(event:MouseEvent) : void
        {
            (event.currentTarget.getChildByName("label") as Label).color = "0xb29a6c";
            return;
        }// end function

        private function lookHandler(event:Event) : void
        {
            Server.instance.send(114, 7, this.data.rid, 0, ConnectType.SYSTEM);
            return;
        }// end function

        private function teamHandler(event:Event) : void
        {
            PluginManager.instance.sendToServer("team", CMDteam.TEAM_INVITE, this.data.rid);
            return;
        }// end function

        private function btnHandler2(event:Event) : void
        {
            PluginManager.instance.sendToServer("team", CMDteam.TEAM_APPLY, this.data.rid);
            return;
        }// end function

        private function btnHandler3(event:Event) : void
        {
            ModelProxy.change("chat", "pritalk", this.data);
            return;
        }// end function

        private function btnHandler1(event:Event) : void
        {
            PluginManager.instance.sendToServer("team", CMDteam.TEAM_INVITE, this.data.rid);
            return;
        }// end function

        private function otherMenu(event:Event) : void
        {
            var _loc_2:* = UserData.getUserData("level");
            if (_loc_2 < 60)
            {
                WarningManager.show(30, [60, "交易"]);
                return;
            }
            var _loc_3:* = this._curSelect.rid;
            ModelProxy.change("plugin", "sendSysMsg", {name:"business", param:_loc_3, cmd:1});
            return;
        }// end function

        private function dispose(event:MouseEvent) : void
        {
            var _loc_2:SelectViewBufferItem = null;
            if (event)
            {
                this.closeHandler();
            }
            ModelProxy.change("data", "selectPlayer", null);
            if (parent)
            {
                visible = false;
            }
            for each (_loc_2 in this.skillBuffers)
            {
                
                if (_loc_2.parent)
                {
                    _loc_2.parent.removeChild(_loc_2);
                }
                _loc_2.dispose();
            }
            DestroyUtil.destroyMap(this.skillBuffers);
            return;
        }// end function

        private function onResize2(event:Event) : void
        {
            this.x = int(GlobalLayer.instance.root.stageWidth - 350 >> 1);
            this.y = 0;
            return;
        }// end function

    }
}
